//无重叠随机排列元素位置

function createdPlace(dom, arr) {
	var html = '';
	var randomArr=[]
    let count = arr.length>20?20:arr.length;//限制20个
    const showHeight = dom.clientHeight-160;   //限制生成区域高度
    const showWidth = dom.clientWidth-250;
    while (count > 0) {
        const row = Math.floor(Math.random() * showHeight)
        const col = Math.floor(Math.random() * showWidth)
        if (randomArr.length === 0) {
            randomArr.push({
                left: col,
                top: row
            })
            count -= 1
        } else {
            const noOverlap = randomArr.every(v => Math.hypot(v.left - col, v.top - row) > 250)  //每次随机生成的点位置不会有重叠
            if (noOverlap) {
                randomArr.push({
                    left: col,
                    top: row
                })
                count -= 1
            }
        }
    }
	for (var k=0;k<randomArr.length;k++) {
		html += `<div style='top:${randomArr[k].top}px;left:${randomArr[k].left}px'><img class="objcover" src='${arr[k].img}'/></div>`;
	}

	dom.innerHTML = html;
}